<title>商户审核</title>
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>商户管理</cite></a>
    <a><cite>商户审核</cite></a>
  </div>
</div>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab-content">
      <div class="layui-btn-group demoTable lay-mb15">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
          <div class="layui-form-item" style="margin:0;">
            <div class="layui-form-item" style="margin:0;">
              <div class="layui-inline">
                <label class="layui-form-label">商户ID</label>
                <div class="layui-input-block">
                  <input type="text" name="mchId" id="mchId" placeholder="商户ID" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-inline">
                <button id="search" class="layui-btn layuiadmin-btn-admin" data-type="reload">
                  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
              </div>

            </div>
          </div>
        </div>
      </div>
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <!--<a class="layui-btn layui-btn-normal" data-type="add" lay-href="merchant/list/mch_add"><i class="layui-icon"></i>添加商户</a>-->
          <!--<a class="layui-btn layui-btn-warm" data-type="export" lay-href="merchant/list/mch_add"><i class="layui-icon layui-icon-download-circle"></i>导出数据</a>-->

          <!--<button id="addChannelMch" class="layui-btn layui-btn-normal" data-type="add"><i class="layui-icon"></i>添加-->
          <!--</button>-->
          <!--<button id= "output" class="layui-btn layui-btn-warm" data-type="output"><i class="layui-icon layui-icon-download-circle"></i>导出-->
          <!--</button>-->
          <!--<button id= "batchdel" class="layui-btn layui-btn-danger" data-type="batchdel"><i class="layui-icon"></i>删除-->
          <!--</button>-->
        </div>
        <table id="XxPay_Mgr_Audit_dataAll" lay-filter="XxPay_Mgr_Audit_dataAll"></table>
      </div>
    </div>
  </div>
</div>

<script type="text/html" id="auditBar">
  <div class="opetate">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="audit_pass">通过</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="audit_refuse">拒绝</a>

  </div>
  <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="audit">审核</a>-->
  <!--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
</script>

<script>
  layui.use(['admin', 'table', 'util'], function(){
    var $ = layui.$
      ,admin = layui.admin
      ,table = layui.table
      ,element = layui.element
      ,form = layui.form;

    element.render('breadcrumb', 'breadcrumb');

    var tplStatus = function(d){
      if(d.status == -1) {
        return "<span style='color: orange'>等待审核</span>";
      }else if(d.status == -2) {
        return "<span style='color: red'>审核不通过</span>";
      }
    };

    //商户列表
    table.render({
      elem: '#XxPay_Mgr_Audit_dataAll'
      ,url: layui.setter.baseUrl + '/mch_audit/list' //列表接口
      ,where: {
          access_token: layui.data(layui.setter.tableName).access_token
      }
      ,id: 'tableReload'
      ,page: true
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field: 'mchId', title: '商户ID'}
        ,{field: 'name', title: '商户名称'}
        ,{field: 'status', title: '状态', templet: tplStatus}
        ,{field: 'createTime', title: '时间', width: 200, templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'}
        ,{field: 'edit', title: '操作', width: 320, toolbar: '#auditBar' }
      ]]
      ,skin: 'line'
    });

    //监听工具条
    table.on('tool(XxPay_Mgr_Audit_dataAll)', function(obj){
      var data = obj.data;
      if(obj.event === 'audit_pass'){
          admin.req({
              type: "POST",
              url: layui.setter.baseUrl + '/mch_audit/audit',
              data: {
                  mchId : data.mchId,
                  status:1
              },
              success: function(res){
                  if(res.code == 0) {
                      layer.alert(res.msg, {title: "审核通过"}, function(index){
                          layer.close(index);
                         // location.href = layui.setter.baseLocal + 'merchant/audit/';
                      });
                  }
              }
          });
      }else if(obj.event === 'audit_refuse'){
          admin.req({
              type: "POST",
              url: layui.setter.baseUrl + '/mch_audit/audit',
              data: {
                  mchId : data.mchId,
                  status:-2
              },
              success: function(res){
                  if(res.code == 0) {
                      layer.alert(res.msg, {title: "审核通过"}, function(index){
                          layer.close(index);
                          // location.href = layui.setter.baseLocal + 'merchant/audit/';
                      });
                  }
              }
          });

      } else if(obj.event === 'edit'){
        location.href = layui.setter.baseLocal + "merchant/audit/mch_edit/mchId=" + data.mchId;
      }
    });

    // 搜索
    var $ = layui.$, active = {
      reload: function(){
        var mchId = $('#mchId').val();
        var type = $("#type").val();
        //执行重载
        table.reload('tableReload', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: {
            mchId: mchId,
            type : type
          }
        });
      }
    };
    $('#search').on('click', function() {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    // 渲染表单
    form.render();
  });
</script>